我正在玩RubyonRails,我正在尝试创建一个带有可选参数的方法。显然有很多方法可以做到这一点。我尝试将可选参数命名为散列,而不定义它们。输出不同。看一看:#Thisfunctionsworksfine!defmy_info(name,options={})age=options[:age]||27weight=options[:weight]||160city=options[:city]||"NewYork"puts"Mynameis#{name},myageis#{age},myweightis#{weight}andIlivein{city}"endmy_info"Bill
选择有意义。但是有人可以向我解释.detect吗?我不明白这些数据。>>[1,2,3,4,5,6,7].detect{|x|x.between?(3,4)}=>3>>[1,2,3,4,5,6,7].detect{|x|x.between?(3,6)}=>3>>[1,2,3,4,5,6,7].detect{|x|x.between?(3,7)}=>3>>[1,2,3,4,5,6,7].detect{|x|x.between?(2,7)}=>2>>[1,2,3,4,5,6,7].detect{|x|x.between?(1,7)}=>1>>[1,2,3,4,5,6,7].detect{|x